package com.github.rpc4j.producer.util;

import java.lang.reflect.Method;

import com.github.rpc4j.common.ServiceRequest;

/**
 * Util Tool
 * @author yuncheng
 *
 */
public final class Utils {
    
	 /**
	  * get method string key
	  * @param method
	  * @return
	  */
	 public static String getMethodKey(Method method){
		 StringBuffer sb = new StringBuffer();
		 String name = method.getName();
		 sb.append(name).append("_");
		 Class[] paramClasses = method.getParameterTypes();
		 if(paramClasses==null||paramClasses.length==0)
			 return sb.toString();
		 for(Class paramClass:paramClasses){
			 sb.append(paramClass.getName()).append("_");
		 }
		 return sb.toString();
	}
	 
	 /**
	  * get  ServiceRequest string key
	  * @param method
	  * @return
	  */
	 public static String getServiceRequestMethodKey(ServiceRequest request){
		 StringBuffer sb = new StringBuffer();
		 String name = request.getMethod();
		 sb.append(name).append("_");
		 Object[] paramClasses = request.getServiceArgs();
		 if(paramClasses==null||paramClasses.length==0)
			 return sb.toString();
		 for(Object paramClass:paramClasses){
			 sb.append(paramClass.getClass().getName()).append("_");
		 }
		 return sb.toString();
	}
	 
	 
	
}
